import { useAuthStore } from '~/stores/auth';

export function usePermission() {
  const user = useAuthStore(state => state.user);

  const hasPermission = (permission: string) => {
    if (!user || !user.permissions) return false;
    return user.permissions.includes(permission);
  };

  const checkPermissions = (permissions: string[], mode: 'every' | 'some' = 'every') => {
    if (!user || !user.permissions) return false;
    return mode === 'every' 
      ? permissions.every(p => user.permissions.includes(p))
      : permissions.some(p => user.permissions.includes(p));
  };

  return { hasPermission, checkPermissions };
}